import { Component, OnInit } from '@angular/core';
import { HybDriverDetailInfoDto, HybDriverAuditInfoDto} from '../HuoMesstmp.model';
import { ApiService } from '../../../../providers/ApiPro.service';
import { ActivatedRoute, Router, RouterLink, RouterModule } from '@angular/router';
import { NzModalService } from 'ng-zorro-antd';



@Component({
  selector: 'app-MessDriverInfo',
  templateUrl: './MessDriverInfo.component.html',
  styleUrls: ['./MessDriverInfo.component.scss']
})
export class MessDriverInfoComponent implements OnInit {
    data = [];
    public driverInfo: HybDriverDetailInfoDto = new HybDriverDetailInfoDto();
    public showCheck: boolean = false;
    public driverAudit: HybDriverAuditInfoDto = new HybDriverAuditInfoDto();
  constructor(
    private apiService: ApiService,
    private route: ActivatedRoute,
    private router: Router,
    private confirmServ: NzModalService


  ) { }

  ngOnInit() {
    this.getId();
  }

  getId(){
     this.route.params.subscribe((params) => {
            this.load(params['id']);
            this.loadTable(params['id']);
            if(params['edit'] == 'edit' ){
              this.showCheck = true;
            }// 通过这个方法来判断是否为审核
        });

  }

  load(id){
    let url = "finddriverdetail"
    this.apiService.get(url,{"driverId":id})
      .then(res =>{
        this.driverInfo = res.result;
        this.driverAudit.auditStatus = this.driverInfo.auditStatus;
      })
  }
  
  loadTable(id){
    let url = "finddriverordertakingdetail"
    this.apiService.get(url,{"driverId":id})
      .then(res =>{
        this.data = res.result;
      })
  }

  upAudit(){
     this.route.params.subscribe((params) => {
            this.driverAudit.driverId = params['id']
        });
    let url = "auditdriver";
    this.apiService.post(url,this.driverAudit)
        .then(res =>{
          console.log(res);
          if(res.result){
            this.success();
          }else{
            this.warning();
          }
        })
  }

  success(){
    let self = this;
      this.confirmServ.success({
      title: '成功',
      content: '司机审核成功',
      okText:'保存完毕',
      onOk() {
        self.router.navigateByUrl("layout/mess/driverinfo/"+self.driverAudit.driverId);
      },
    });
  }

  warning() {
    this.confirmServ.warning({
      title: '警告',
      content: '传入的审核状态,就是司机的当前状态,所以不用修改'
    });
  }


}
